package com.loong.seller.handler;

import com.loong.common.domain.BaseQuery;
import com.loong.common.domain.Pager;
import com.loong.common.utils.TransformUtils;
import com.loong.seller.business.DeliveryWaysBusiness;
import com.loong.seller.common.backend.param.DeliveryWaysParam;
import com.loong.seller.common.backend.param.DeliveryWaysQueryParam;
import com.loong.seller.common.backend.result.DeliveryWaysResult;
import com.loong.seller.common.forehead.result.DeliveryWaysForeheadResult;
import com.loong.seller.model.DeliveryWays;
import com.loong.seller.model.dto.DeliveryWaysDto;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author: hzp
 * @Date: 2020-11-9 9:12
 */
@Component
public class DeliveryWaysHandler {
    @Resource
    private DeliveryWaysBusiness deliveryWaysBusiness;


    /**
     * 保存配送方式
     * @param param 配送方式
     */
    public void save(DeliveryWaysParam param){
        deliveryWaysBusiness.save(TransformUtils.transform(param, DeliveryWays.class));
    }

    /**
     * 更新配送方式
     * @param param 配送方式
     */
    public void update(DeliveryWaysParam param){
        deliveryWaysBusiness.updateByPrimaryKeySelective(TransformUtils.transform(param, DeliveryWays.class));
    }

    /**
     *根据id删除配送方式
     * @param ids 配送方式id
     */
    public void deleteByIds(List<Long> ids){
        //TODO 资源判断
        if(CollectionUtils.isEmpty(ids))return;
        deliveryWaysBusiness.deleteByIds(StringUtils.join(ids,","));
    }
    /**
     * 分页查询
     * @param baseQuery 分页对象
     * @param param 分页参数
     * @return
     */
    public Pager<DeliveryWaysResult> pageQuery(BaseQuery baseQuery, DeliveryWaysQueryParam param){
        Pager<DeliveryWays> deliveryWaysPager = deliveryWaysBusiness.pageQuery(baseQuery, () -> deliveryWaysBusiness.query(param));
        return TransformUtils.transformPage(deliveryWaysPager, DeliveryWaysResult.class);
    }

    /**
     * c端使用  查询所有的 配送方式
     * @return
     */
    public List<DeliveryWaysForeheadResult> findAll() {
        return TransformUtils.transformList(deliveryWaysBusiness.findAll(),DeliveryWaysForeheadResult.class);
    }

    /**
     * 下拉列表
     * @return
     */
    public List<DeliveryWaysResult> findAllList() {
        return TransformUtils.transformList(deliveryWaysBusiness.findAll(),DeliveryWaysResult.class);
    }

    public List<DeliveryWaysResult> findDetailByShopId(Long shopId) {
        return TransformUtils.transformList(deliveryWaysBusiness.findDetailByShopId(shopId),DeliveryWaysResult.class);
    }

    public List<DeliveryWays> findDeliveryWaysByIds(List<Long> ids){
       return deliveryWaysBusiness.findByIds(StringUtils.join(ids,","));
    }

    public List<DeliveryWaysDto> findDeliveryWaysByShopId(Long shopId){
        return deliveryWaysBusiness.findDeliveryWaysByShopId(shopId);
    }
    public List<DeliveryWaysForeheadResult> findDeliveryWaysByShopIdForehead(Long shopId){
        return TransformUtils.transformList(deliveryWaysBusiness.findDeliveryWaysByShopId(shopId),DeliveryWaysForeheadResult.class);
    }
}
